package models;

import com.avaje.ebean.Page;
import play.data.validation.Constraints;
import play.db.ebean.Model;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Thanhnv
 * Date: 4/22/12
 * Time: 8:41 AM
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class CustomerInformation extends Model {

    @Id
    public Long id;

    @Constraints.Required
    public String name;

    public String address;

    public String description;

    public static Model.Finder<Long,CustomerInformation> find = new Model.Finder<Long,CustomerInformation>(Long.class, CustomerInformation.class);

    public static List<CustomerInformation> all(){
        List<CustomerInformation> tasks = CustomerInformation.find.all();
        return tasks;
    }

    public static Page<CustomerInformation> page(int page, int pageSize, String sortBy, String order, String filter) {
        System.out.println("bbbb:"+filter);
        return find.where()
                .ilike("name", "%" + filter + "%")
                .orderBy(sortBy + " " + order)
                .findPagingList(pageSize)
                .getPage(page);
    }


    public String toString()  {
        return name + " " +address + " " +description;
    }
}
